package com.ibm.ems.servlets;

import java.io.IOException;

import java.sql.Connection;
import java.util.ArrayList;




import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.ems.dao.LocationDAO;
import com.ibm.ems.dto.LocationBean;
import com.ibm.ems.util.ConnectionUtil;

/**
 * Servlet implementation class TopicServlet
 */
public class LocationServlet extends HttpServlet {
	Connection conn;
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public LocationServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		
		Connection conn = ConnectionUtil.getConnection();
		LocationDAO td = new LocationDAO(conn);
		
		
		
		
	
	if(request.getParameter("modify")!=null)
	{
		
		
		LocationBean mod=new LocationBean();
		
		mod.setLocationId(request.getParameter("loc_code"));
	
		mod.setLocationCity(request.getParameter("city"));
		mod.setLocationState(request.getParameter("state"));
		mod.setLocationDesc(request.getParameter("desc"));
		td.modifydatabase(mod);
			
	}
	
		

	System.out.println(request.getParameter("create"));
if(request.getParameter("create")!=null)
{
	LocationBean t1=new LocationBean();
	t1.setLocationId(request.getParameter("loc_code"));
	
	t1.setLocationCity(request.getParameter("city"));
	t1.setLocationState(request.getParameter("state"));
	t1.setLocationDesc(request.getParameter("desc"));
	
	td.LocationDaoCreate(t1);
	
}
System.out.println("sd");
ArrayList<LocationBean> l=new ArrayList<LocationBean>();
td.LocationDaoInit(l);
RequestDispatcher rd=request.getRequestDispatcher("/EventManagementSystem/LocationPage.jsp");
request.setAttribute("a",l);
rd.forward(request, response);	

		
	}
	 

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		// TODO Auto-generated method stub
	}

}
